/*   1:    */ package org.jetbrains.jps.model.ex;
/*   2:    */ 
/*   3:    */

import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.*;
import org.jetbrains.jps.model.JpsElement.BulkModificationSupport;

import java.util.Iterator;
import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */ 
/*  18:    */ public class JpsElementContainerImpl
/*  19:    */   extends JpsElementContainerEx
/*  20:    */   implements JpsElementContainer
/*  21:    */ {
/*  22: 29 */   private final Map<JpsElementChildRole<?>, JpsElement> a = new THashMap(1);
/*  23:    */   @NotNull
/*  24:    */   private final JpsCompositeElementBase<?> b;
/*  25:    */   
/*  26:    */   public JpsElementContainerImpl(@NotNull JpsCompositeElementBase<?> paramJpsCompositeElementBase)
/*  27:    */   {
/*  28: 33 */     this.b = paramJpsCompositeElementBase;
/*  29:    */   }
/*  30:    */   
/*  31:    */   public JpsElementContainerImpl(@NotNull JpsElementContainerEx paramJpsElementContainerEx, @NotNull JpsCompositeElementBase<?> paramJpsCompositeElementBase)
/*  32:    */   {
/*  33: 37 */     this.b = paramJpsCompositeElementBase;
/*  34: 38 */     for (Map.Entry localEntry : paramJpsElementContainerEx.getElementsMap().entrySet())
/*  35:    */     {
/*  36: 39 */       JpsElementChildRole localJpsElementChildRole = (JpsElementChildRole)localEntry.getKey();
/*  37: 40 */       JpsElement localJpsElement = ((JpsElement)localEntry.getValue()).getBulkModificationSupport().createCopy();
/*  38: 41 */       JpsElementBase.setParent(localJpsElement, this.b);
/*  39: 42 */       this.a.put(localJpsElementChildRole, localJpsElement);
/*  40:    */     }
/*  41:    */   }
/*  42:    */   
/*  43:    */   public <T extends JpsElement> T getChild(@NotNull JpsElementChildRole<T> paramJpsElementChildRole)
/*  44:    */   {
/*  45: 49 */     if (paramJpsElementChildRole == null) {
/*  46: 49 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "getChild" }));
/*  47:    */     }
/*  48: 49 */     return (JpsElement)this.a.get(paramJpsElementChildRole);
/*  49:    */   }
/*  50:    */   
/*  51:    */   @NotNull
/*  52:    */   public <T extends JpsElement, P, K extends JpsElementChildRole<T>,  extends JpsElementParameterizedCreator<T, P>> T setChild(@NotNull K paramK, @NotNull P paramP)
/*  53:    */   {
/*  54: 56 */     if (paramK == null) {
/*  55: 56 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "setChild" }));
/*  56:    */     }
/*  57: 56 */     if (paramP == null) {
/*  58: 56 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "setChild" }));
/*  59:    */     }
/*  60: 56 */     JpsElement localJpsElement = ((JpsElementParameterizedCreator)paramK).create(paramP); JpsElement 
/*  61: 57 */       tmp97_94 = setChild(paramK, localJpsElement);
/*  62: 57 */     if (tmp97_94 == null) {
/*  63: 57 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "setChild" }));
/*  64:    */     }
/*  65: 57 */     return tmp97_94;
/*  66:    */   }
/*  67:    */   
/*  68:    */   @NotNull
/*  69:    */   public <T extends JpsElement, K extends JpsElementChildRole<T>,  extends JpsElementCreator<T>> T setChild(@NotNull K paramK)
/*  70:    */   {
/*  71: 63 */     if (paramK == null) {
/*  72: 63 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "setChild" }));
/*  73:    */     }
/*  74: 63 */     JpsElement localJpsElement = ((JpsElementCreator)paramK).create(); JpsElement 
/*  75: 64 */       tmp56_53 = setChild(paramK, localJpsElement);
/*  76: 64 */     if (tmp56_53 == null) {
/*  77: 64 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "setChild" }));
/*  78:    */     }
/*  79: 64 */     return tmp56_53;
/*  80:    */   }
/*  81:    */   
/*  82:    */   @NotNull
/*  83:    */   public <T extends JpsElement, K extends JpsElementChildRole<T>,  extends JpsElementCreator<T>> T getOrSetChild(@NotNull K paramK)
/*  84:    */   {
/*  85: 70 */     if (paramK == null) {
/*  86: 70 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "getOrSetChild" }));
/*  87:    */     }
/*  88: 70 */     JpsElement localJpsElement = getChild(paramK);
/*  89: 71 */     if (localJpsElement == null)
/*  90:    */     {
/*  91: 72 */       JpsElement tmp55_52 = setChild(paramK);
/*  92: 72 */       if (tmp55_52 == null) {
/*  93: 72 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "getOrSetChild" }));
/*  94:    */       }
/*  95: 72 */       return tmp55_52;
/*  96:    */     }
/*  97: 74 */     JpsElement tmp91_90 = localJpsElement;
/*  98: 74 */     if (tmp91_90 == null) {
/*  99: 74 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "getOrSetChild" }));
/* 100:    */     }
/* 101: 74 */     return tmp91_90;
/* 102:    */   }
/* 103:    */   
/* 104:    */   public <T extends JpsElement> T setChild(JpsElementChildRole<T> paramJpsElementChildRole, T paramT)
/* 105:    */   {
/* 106: 79 */     this.a.put(paramJpsElementChildRole, paramT);
/* 107: 80 */     JpsElementBase.setParent(paramT, this.b);
/* 108: 81 */     JpsEventDispatcher localJpsEventDispatcher = a();
/* 109: 82 */     if (localJpsEventDispatcher != null) {
/* 110: 83 */       localJpsEventDispatcher.fireElementAdded(paramT, paramJpsElementChildRole);
/* 111:    */     }
/* 112: 85 */     return paramT;
/* 113:    */   }
/* 114:    */   
/* 115:    */   public <T extends JpsElement> void removeChild(@NotNull JpsElementChildRole<T> paramJpsElementChildRole)
/* 116:    */   {
/* 117: 91 */     if (paramJpsElementChildRole == null) {
/* 118: 91 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "removeChild" }));
/* 119:    */     }
/* 120: 91 */     JpsElement localJpsElement = (JpsElement)this.a.remove(paramJpsElementChildRole);
/* 121: 92 */     if (localJpsElement == null) {
/* 122: 92 */       return;
/* 123:    */     }
/* 124: 93 */     JpsEventDispatcher localJpsEventDispatcher = a();
/* 125: 94 */     if (localJpsEventDispatcher != null) {
/* 126: 95 */       localJpsEventDispatcher.fireElementRemoved(localJpsElement, paramJpsElementChildRole);
/* 127:    */     }
/* 128: 97 */     JpsElementBase.setParent(localJpsElement, null);
/* 129:    */   }
/* 130:    */   
/* 131:    */   protected Map<JpsElementChildRole<?>, JpsElement> getElementsMap()
/* 132:    */   {
/* 133:102 */     return this.a;
/* 134:    */   }
/* 135:    */   
/* 136:    */   public void applyChanges(@NotNull JpsElementContainerEx paramJpsElementContainerEx)
/* 137:    */   {
/* 138:106 */     if (paramJpsElementContainerEx == null) {
/* 139:106 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/ex/JpsElementContainerImpl", "applyChanges" }));
/* 140:    */     }
/* 141:106 */     for (Iterator localIterator = this.a.keySet().iterator(); localIterator.hasNext();)
/* 142:    */     {
/* 143:106 */       localJpsElementChildRole = (JpsElementChildRole)localIterator.next();
/* 144:107 */       a(localJpsElementChildRole, paramJpsElementContainerEx);
/* 145:    */     }
/* 146:    */     JpsElementChildRole localJpsElementChildRole;
/* 147:109 */     for (localIterator = paramJpsElementContainerEx.getElementsMap().keySet().iterator(); localIterator.hasNext();)
/* 148:    */     {
/* 149:109 */       localJpsElementChildRole = (JpsElementChildRole)localIterator.next();
/* 150:110 */       if (!this.a.containsKey(localJpsElementChildRole)) {
/* 151:111 */         a(localJpsElementChildRole, paramJpsElementContainerEx);
/* 152:    */       }
/* 153:    */     }
/* 154:    */   }
/* 155:    */   
/* 156:    */   private <T extends JpsElement> void a(JpsElementChildRole<T> paramJpsElementChildRole, JpsElementContainerEx paramJpsElementContainerEx)
/* 157:    */   {
/* 158:117 */     JpsElement localJpsElement1 = getChild(paramJpsElementChildRole);
/* 159:118 */     JpsElement localJpsElement2 = paramJpsElementContainerEx.getChild(paramJpsElementChildRole);
/* 160:119 */     if ((localJpsElement1 != null) && (localJpsElement2 != null))
/* 161:    */     {
/* 162:120 */       JpsElement.BulkModificationSupport localBulkModificationSupport = localJpsElement1.getBulkModificationSupport();
/* 163:    */       
/* 164:122 */       localBulkModificationSupport.applyChanges(localJpsElement2);
/* 165:    */     }
/* 166:124 */     else if (localJpsElement2 == null)
/* 167:    */     {
/* 168:125 */       removeChild(paramJpsElementChildRole);
/* 169:    */     }
/* 170:    */     else
/* 171:    */     {
/* 172:129 */       setChild(paramJpsElementChildRole, localJpsElement2.getBulkModificationSupport().createCopy());
/* 173:    */     }
/* 174:    */   }
/* 175:    */   
/* 176:    */   @Nullable
/* 177:    */   private JpsEventDispatcher a()
/* 178:    */   {
/* 179:135 */     return this.b.getEventDispatcher();
/* 180:    */   }
/* 181:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.ex.JpsElementContainerImpl

 * JD-Core Version:    0.7.0.1

 */